package com.zhtools.excel.tester;

import com.zhtools.excel.Column;
import com.zhtools.excel.TypeHandler;
import com.zhtools.excel.reader.SimpleExcelReader;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class SimpleExcelRead extends SimpleExcelReader<Order> {
    @Override
    protected List<Column> columns() {
        List<Column> columns = new ArrayList<>();
        columns.add(new Column(0, "orderId"));
        columns.add(new Column(1, "orderCode"));
        columns.add(new Column(2, "price"));
        columns.add(new Column(3, "createTime", new TypeHandler<Date>() {
            @Override
            public Date getValue(String value) {
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = null;
                try {
                    date = dateFormat.parse(value);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return date;
            }
        }));
        columns.add(new Column(4, "score"));
        return columns;
    }

    public static void main(String[] args) {
        SimpleExcelRead simpleExcelRead = new SimpleExcelRead();
        List<Order> orders = simpleExcelRead.read("/Users/zhanghao/测试3.xlsx",0);
        System.out.println(orders.size());
    }
}
